package com.estate.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.estate.dao.RecordMemberDao;
import com.estate.vo.Vo;
import com.estate.vo.impl.RecordMemberVo;

public class RecordMemberDaoImpl implements RecordMemberDao {

private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory(){
		return this.sessionFactory;
	}
	
	public void setSessionFactory(SessionFactory sessionFactory){
		this.sessionFactory=sessionFactory;
	}
	public boolean addVo(Vo vo) {
		this.getSessionFactory().getCurrentSession().save(vo);
		return true;
	}

	public boolean deleteVo(Vo vo) {
		this.getSessionFactory().getCurrentSession().delete(vo);
		return true;
	}

	public List<Vo> findAll() {
		Query query = this.getSessionFactory().getCurrentSession().createQuery("from RecordMemberVo");
		List<Vo> voList = query.list();
		return voList;
	}

	public Vo findByPK(Object pk) {
		Vo vo = (Vo) this.getSessionFactory().getCurrentSession().get(RecordMemberVo.class, (Integer)pk);
		return vo;
	}

	public boolean updateVo(Vo vo) {
		this.getSessionFactory().getCurrentSession().merge(vo);
		return true;
	}

	public Vo findMember(int proCatagory, int proId, int id) {
		// TODO Auto-generated method stub
		Query query = this.getSessionFactory().getCurrentSession().createQuery("from RecordMemberVo where recordUserId=:recordUserId and proId=:proId and proCatagory=:proCatagory").setInteger("recordUserId", id).setInteger("proId", proId).setInteger("proCatagory", proCatagory);
		Vo voList = (Vo) query.uniqueResult();
		return voList;
	}

	public List<Vo> findMemberList(int proCatagory, int proId) {
		// TODO Auto-generated method stub
		Query query = this.getSessionFactory().getCurrentSession().createQuery("from RecordMemberVo where proCatagory=:proCatagory and proId=:proId").setInteger("proCatagory", proCatagory).setInteger("proId", proId);
		List<Vo> voList = query.list();
		return voList;
	}

}
